<?php
class sfWidgetFormMonthCompare extends sfWidgetForm {

	protected function configure($options = array(), $attributes = array())
	{

	}


	public function render($name, $value = null, $attributes = array(), $errors = array())
	{
		$mon_wid       = new sfWidgetFormChoice( array ( 'choices'=>$this->range(1,date('m'))));
		$mon_with_wid  = new sfWidgetFormChoice( array ( 'expanded'=>true,'multiple'=>true,'choices'=>$this->range(1,date('m')-1)) ,array('rows'=>5));
		$wid_year = new sfWidgetFormChoice( array ( 'choices'=>$this->range( 2000 , date('Y') )));
		
		
		$compare_month_value = isset($value['compare_month']) ? $value['compare_month'] : null;
		$compare_with_month_value = isset($value['compare_with_month']) && is_array($value['compare_with_month']) & count($value['compare_with_month']) > 0? $value['compare_with_month'] : null;
		$compare_with_year_value = isset($value['compare_with_year']) ? $value['compare_with_year'] : null;
		
		$html = $mon_wid->render($name.'[compare_month]',$compare_month_value);
		$html .= ' With Month';
		$html .= ' ';
		$html .= $mon_with_wid->render($name.'[compare_with_month]',$compare_with_month_value);
		$html .= ' ';
		$html .= $wid_year->render($name.'[compare_with_year]',$compare_with_year_value);
		
		return $html;
	}
	
	protected function range($start , $end){
		$arr = range( $start , $end );
		$arr2 = array();
		foreach ($arr as $v) {
			$arr2[$v] = $v;
		}
		return $arr2;
	}
	
}